package gcommand

/*******************************************************************************
Copyright:cloud
Author:cloudapex@126.com
Version:1.0
Date:2014-10-18
Description:登陆视图窗口
	1 调用Create(owner , mode)
	2 调用Run()
	2 init window and bind mode
	3 调用control相关控制接口
*******************************************************************************/
import (
	. "Ghost/utd"
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
)

var TheViewLogin *LoginDialog = &LoginDialog{}

type LoginDialog struct {
	*walk.Dialog
}

func (this *LoginDialog) Created() bool { return this.Dialog != nil }
func (this *LoginDialog) Create(owner walk.Form, mode IDataBinder) {
	var databind *walk.DataBinder
	var acceptPBtn *walk.PushButton

	if err := (Dialog{
		AssignTo:      &this.Dialog,
		Title:         "登录",
		FixedSize:     true,
		DefaultButton: &acceptPBtn,
		DataBinder: DataBinder{
			AssignTo:       &databind,
			DataSource:     mode,
			ErrorPresenter: ToolTipErrorPresenter{},
			AutoSubmit:     true,
		},

		Size:   Size{400, 220},
		Layout: VBox{},
		Children: []Widget{
			Composite{
				Layout: Grid{Columns: 2, Margins: Margins{10, 10, 10, 0}, Spacing: 10},
				Children: []Widget{
					Label{
						Font: Font{Family: "微软雅黑", PointSize: 14},
						Text: "服务地址:",
					},
					LineEdit{
						Font: Font{Family: "微软雅黑", PointSize: 14},
						Text: Bind("RoostHost"),
					},

					Label{
						Font: Font{Family: "微软雅黑", PointSize: 14},
						Text: "登录账号:",
					},
					LineEdit{
						Font: Font{Family: "微软雅黑", PointSize: 14},
						Text: Bind("Account"),
					},

					Label{
						Font: Font{Family: "微软雅黑", PointSize: 14},
						Text: "登陆密码:",
					},
					LineEdit{
						Font: Font{Family: "微软雅黑", PointSize: 14},
						Text: Bind("Password"),
					},
				},
			},
			Composite{
				StretchFactor: 2,
				Layout:        VBox{Margins: Margins{90, 0, 90, 0}},
				Children: []Widget{
					Label{
						MinSize: Size{0, 20},
						Font:    Font{Family: "微软雅黑", PointSize: 10, Bold: true},
						Text:    Bind("ErrorTip"),
					},
					PushButton{
						AssignTo: &acceptPBtn,
						Text:     Bind("LoginText"),
						Font:     Font{Family: "微软雅黑", PointSize: 14},
						OnClicked: func() {
							databind.Submit()
							TheCtrl.ConnectRoost(true)
						},
					},
				},
			},
		},
	}.Create(owner)); err != nil {
		UMain.Fatal(err)
	}

	mode.SetupBinder(databind)
}
